<template>
  <!-- 表单 -->
  <el-form :inline="true" class="search-form">
    <div class="search-form-items">
      <el-form-item label="管理员账号">
        <el-input v-model="params.userAccount" placeholder="请输入要搜索管理员账号" />
      </el-form-item>
      <el-form-item label="管理员昵称">
        <el-input v-model="params.nickName" placeholder="请输入要搜索的管理员昵称" />
      </el-form-item>
      <!-- <el-form-item label="创建人账号">
        <el-input v-model="params.creatorName" placeholder="请输入要搜索的创建人账号" />
      </el-form-item> -->
    </div>
    <div class="search-form-buttons">
      <el-form-item>
        <el-button @click="onSearch" plain>搜索</el-button>
        <el-button @click="onReset" plain type="info">重置</el-button>
      </el-form-item>
    </div>
  </el-form>
  <!-- 表格 -->
  <el-table height="526px" :data="userList">
    <el-table-column prop="sysUserId" label="管理员id"/>
    <el-table-column prop="userAccount" label="管理员账号" />
    <el-table-column prop="nickname" label="昵称" />
    <!-- <el-table-column prop="creatorName" label="创建人账号" /> -->
    <el-table-column prop="createTime" label="创建时间"/>
  </el-table>
  <!-- 分页区域 -->
  <el-pagination background size="small" layout="total, sizes, prev, pager, next, jumper" :total="total"
    v-model:current-page="params.pageNum" v-model:page-size="params.pageSize" :page-sizes="[5, 10, 20, 50]"
    @size-change="handleSizeChange" @current-change="handleCurrentChange" />
</template>

<script setup>
import { reactive, ref } from 'vue';
import { getSysUserListService} from '@/apis/suser'

const params = reactive({
  pageNum: 1,
  pageSize: 10,
  userAccount: '',
  nickName: '',
  creatorName: '',
})

const userList = ref([])
const total = ref(0)

async function getSysUserList() {
  const ref = await getSysUserListService(params)
  userList.value = ref.rows
  total.value = ref.total
}
getSysUserList()


function onSearch() {
  params.pageNum = 1
  getSysUserList()
}

function onReset() {
  params.pageNum = 1
  params.pageSize = 10
  params.userAccount = ''
  params.nickName = ''
  params.creatorName = ''
  getSysUserList()
}

function handleSizeChange(newSize) {
  params.pageNum = 1
  getSysUserList()
}

function handleCurrentChange(newPage) {
  getSysUserList()
}

</script>

<style scoped>
/* 添加响应式表单样式 */
.search-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 20px;
}

.search-form-items {
  display: flex;
  flex-wrap: wrap;
  flex: 1;
}

.search-form-buttons {
  display: flex;
  align-items: flex-start;
  margin-left: auto;
}

.search-form :deep(.el-form-item) {
  margin-right: 20px;
  margin-bottom: 10px;
  min-width: 220px;
}

.search-form :deep(.el-select), 
.search-form :deep(.el-input) {
  width: 220px;
}

@media (max-width: 1200px) {
  .search-form {
    flex-direction: column;
  }
  
  .search-form-buttons {
    margin-left: 0;
    margin-top: 10px;
  }
}
</style>